﻿<%@ page contentType="text/html; charset=UTF-8" %>

<!-- 操作员管理 -->


<div class="bar_seach_div">

查询条件：<input id="s_fqsysuser_userAccount" name="s_fqsysuser_userAccount" type="text" class="box-input">&nbsp;&nbsp;
<input id="s_fqsysuser" type="button" class="btns" value="查  询">
</div>

<div style="padding: 5px;"><table id="fqsysuser_grid"></table></div>   
<div style="padding: 5px;"><div id="fqsysuser_page"></div>


<div id="fqsysuser_dialog_index" title=" 操作员管理操作"  class="easyui-dialog" >
<form id="fqsysuser_form_index" name="fqsysuser_form_index" style="width:626px;" class="ui-form" method="POST">
    <div id="fqsysuser_index_errmsg"></div>
    <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" class="jkt-tableStyle">

	<tr>
        <td class="bluetd" align="right">帐户：</td>
        <td class="bluetd" align="left">
          <input id="fqsysuser_userAccount_index"  class="easyui-validatebox" type="text"/>
        </td>
     </tr>     <tr>
        <td class="bluetd2" align="right">名称：</td>
        <td class="bluetd2" align="left">
          <input id="fqsysuser_userName_index"  class="easyui-validatebox" data-options="required:true"  type="text" />
        </td>
     </tr>
	<tr>
        <td class="bluetd" align="right">角色分配</td>
        <td class="bluetd" align="left">
        <input id="fqsysuser_roles_index" class="easyui-combobox"  /> 
        </td>
     </tr>
	 
     <tr>
        <td colspan="2" align="center">
          <input type="button" class="btns" id="fqsysuser_index_bt" value="提  交" style="margin-top:8px;" />&nbsp;&nbsp;
          <input type="button" class="btns" id="fqsysuser_close" value="关  闭" style="margin-top:8px;" />
        </td>
     </tr>
</table>
</form>
</div> 

<script>

	//关闭弹出窗口
	closeUIDialog('fqsysuser_dialog_index');
    var fqsysuservalidate,fqsysuserids='',fqsysusersave=true;//本页面变量
     /**jqGrid列表*/
	jQuery("#fqsysuser_grid").jqGrid({
		// caption: 
	    //     '<a href="javascript:fun_fqsysuser_add()"  class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-edit\'">新增</a>' +
	    //     '<a href="javascript:fun_fqsysuser_update()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-save\'">修改</a>' +
	    //     '<a href="javascript:fun_fqsysuser_delete()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-cancel\'">删除</a>',
        datatype: "json", //JSON格式数据
        hidegrid: false, //不显示收缩
        url:'system/SysUser/list.do', //请求后台返回列表数据的URL 
        forceFit: false,//调整宽度不改变表格宽度
        //width: jqGridWidth,   //resources/js/constant.js
        //height: jqGridHeight, //resources/js/constant.js
        autowidth:false,   //取消容器的自动宽度
        colNames:[
        '编号'
        ,'帐户'
        ,'名称'
        ,'状态'
        ,'备注名'
        //,'操作'
	    ],
	    //要呈现字段的属性设置
	    //sortable:设置该字段是否进行排序,sorttype:排序的数据类型 
        colModel:[
        {name:'id',index:'id', width:2,sorttype:'int',sortable:false}  
        ,{name:'userAccount',index:'userAccount',width:80,sortable:false}
        ,{name:'userName',index:'userName',width:80,sortable:false}
        ,{name:'userStatus',index:'userStatus',width:80,sortable:false,formatter: "select", editoptions:{value:"0:無效;1:正常;2:未知"}}
        ,{name:'userNote',index:'userNote',width:80,sortable:false}
        //,{name:'act',        index:'act',   align:'center',     width:150}
        ],
        multiselect: true,//禁止多选
        multiboxonly:true,
        toolbar:[true,'top'],
        rowNum:10, 
        rowList:[10,20,30,50,100,500], 
        viewrecords: true, 
        sortname:  "userId" , //默认排序的列名    
        sortorder: "desc", 
        pager: '#fqsysuser_page', 
        jsonReader: {     
          root: 'dataRows',   
          repeatitems : false     
        }
        //,caption:'操作员管理 列表'       
       // ,gridComplete: function(){  
          //  var ids = $("#fqsysuser_grid").jqGrid('getDataIDs');  
           // for(var i=0, j=ids.length; i < j; i++){  
              //  var cl = ids[i];  
               // be = "<input style='height:22px;width:40px;' type='button' value='编辑' onclick=\"fun_fqsysuser_update();\"  />&nbsp;&nbsp;";   
                //se = "<input style='height:22px;width:40px;' type='button' value='保存' onclick=\"$('#jqGridId').saveRow('"+cl+"');\"  />&nbsp;&nbsp;";  
               // se = "<input style='height:22px;width:40px;' type='button' value='删除' onclick=\"fun_fqsysuser_delete();\"  />&nbsp;&nbsp;";   
               // ce = "";
                //$("#fqsysuser_grid").jqGrid('setRowData',ids[i], {act: be + se + ce});  
           // }
        //}
    })
    
    $("#t_fqsysuser_grid").removeClass("ui-userdata ui-state-default"); //删样式
	$("#t_fqsysuser_grid").append("<div style='height:32px;' class='ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix'><span class='ui-jqgrid-title'>"
	  +""
	  +"<a data-options='plain:true,iconCls:\'icon-save\'' class='easyui-linkbutton l-btn l-btn-plain' href='javascript:fun_fqsysuser_update()' group='' id=''><span class='l-btn-left'><span class='l-btn-text icon-save l-btn-icon-left'>管理员赋权</span></span></a>"
	  +""
	  +"</span></div> ");//列表头

    //$("#t_fqsysuser_grid").append("<div class='bar_grid_add_div' > <a href='javascript:void(0)' onclick=\"fun_fqsysuser_add()\" >新增</a></div>");//列表头
    //$("#t_fqsysuser_grid").hide();//隐藏标题栏
    jQuery("#fqsysuser_grid").jqGrid('hideCol',['id']);//隐藏列
    $("#fqsysuser_grid").closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'hidden' });//隐藏横向滚动条
  
    /***/
    $('#fqsysuser_index_bt').unbind('click');
    
    
    //关闭窗口
    $('#fqsysuser_close').click(function(){
        $("#fqsysuser_dialog_index").dialog('close');
    })
    
    /**点击按妞*/
    $('#fqsysuser_index_bt').click(function(){
         fqsysuser_update_submit(); 
     })
 

     /**修改操作*/
     function fun_fqsysuser_update(){

         var id =$("#fqsysuser_grid").jqGrid('getGridParam','selrow');
         if(typeof(id) =="string"){
             rowData=jQuery("#fqsysuser_grid").jqGrid('getRowData',id);  
 		    //$("#fqsysuser_dialog_index").dialog('option' , 'title',['修改 操作员管理']);
 		    $("#fqsysuser_form_index")[0].reset();
 	    	//
 	    	from_initRoelsCombox(rowData.id);
 	    	//
 		    //fqsysuservalidate.resetForm(); //重置验证状态
 		    //$("#fqsysuser_dialog_index").dialog("open");
 		    openUIDialog('fqsysuser_dialog_index', true, 660, 420);
             load_fqsysuser_data();
             fqsysusersave=false;
         }else{
        	 $.messager.alert('操作提示', '请至少选择一条记录再操作!'); 
         }
 	}
   /**修改加载数据*/
 	function load_fqsysuser_data(){
 	  $("#fqsysuser_userAccount_index").val(rowData.userAccount);
 	  $("#fqsysuser_userName_index").val(rowData.userName);
 	  $("#baract_barId_index").combobox("setValue",rowData.barId);  //
 	}
    //修改提交
    function  fqsysuser_update_submit(){
		 var from_name="";
		 //由于复选框一般选中的是多个,所以可以循环输出选中的值   
		 jQuery("input[type=checkbox]:checked").each(function(){  
			 from_name = from_name + jQuery(this).val() +",";
         });
		 alert(from_name);
        var roleuserJson="{'userId':'"+rowData.id+"','roles':'"+from_name+"'}";  
        $.ajax({
            type: "POST",
            url:"system/SysUser/fuquan.do",
            data:{
            	roleuserJson : roleuserJson
            },
            dataType: "json",
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            success:function(json){
                if(json.success){
                    $("#fqsysuser_grid").trigger("reloadGrid");
                    $.messager.alert('操作提示', '操作成功!'); 
                }else{
               	 $.messager.alert('操作提示', '操作失败!'); 
                }
            }
       })
    } 
	
	//注意:web服务器 utf-8配置
	$('#s_fqsysuser').click(function(){
         var s_userAccount=encodeURI($('#s_fqsysuser_userAccount').val());
         $("#fqsysuser_grid").setGridParam({url:'system/SysUser/list.do?s_userAccount='+s_userAccount});
         $("#fqsysuser_grid").trigger("reloadGrid");
    })
    
    /** jqgrid宽度高度自适应 begin */ 
    doResize();
	var t=document.documentElement.clientWidth;  
	window.onresize = function(){  
		if(t != document.documentElement.clientWidth){ 
		t = document.documentElement.clientWidth; 
		doResize(); 
		} 
	} 
    
	function doResize() { 
		var ss = getPageSize(); 
		$("#fqsysuser_grid").jqGrid('setGridWidth', ss.WinW-350).jqGrid('setGridHeight', ss.WinH-300); 
	}
	
	function getPageSize() { 
		//http://www.blabla.cn/js_kb/javascript_pagesize_windowsize_scrollbar.html 
		var winW, winH; 
		if(window.innerHeight) {// all except IE 
		winW = window.innerWidth; 
		winH = window.innerHeight; 
		} else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode 
		winW = document.documentElement.clientWidth; 
		winH = document.documentElement.clientHeight; 
		} else if (document.body) { // other 
		winW = document.body.clientWidth; 
		winH = document.body.clientHeight; 
		}  // for small pages with total size less then the viewport  
		return {WinW:winW, WinH:winH}; 
	}
	/** jqgrid宽度高度自适应 begin */

	/**下拉框初始化(角色)  begin */
	
	function from_initRoelsCombox(userId) {
		 
		$.ajax({  
			url:"system/Role/getComboBox.do",
			  cache: false,  
			  dataType:"json", 
			  data:{
				  userId : userId
	          },
			  success: function(result){
			  //http://bbs.csdn.net/topics/380097150?page=1#post-394955602
			   //http://www.jeasyui.com/documentation/combobox.php
			  //http://api.btboys.com/easyui/#
				  var feiqumingxiarr = new Array();
				  feiqumingxiarr =result.list;
			    $("#fqsysuser_roles_index").combobox({  
			        data : feiqumingxiarr,  
			        valueField : 'roleId',  
			        textField : 'roleName',
			        multiple:'true',
			        panelHeight:'auto',
			        width:300,
			        editable:false,
			        formatter:function(row){  
			        	var opts;
			        	if(row.selected==true){
			        	   opts = "<input type='checkbox' checked='true' id='"+row.roleId+"' value='"+row.roleId+"'>"+row.roleName+"</input>";
			        	}else{
			        	   opts = "<input type='checkbox'   id='"+row.roleId+"' value='"+row.roleId+"'>"+row.roleName+"</input>";
			        	}
			        	return opts;
			        },
			        onSelect:function(rec) {
			        	  oCheckbox = document.getElementById(rec.roleId);   
			        	   oCheckbox.checked=true;
			        },onUnselect:function(rec){
			        	  oCheckbox = document.getElementById(rec.roleId);   
			        	  oCheckbox.checked=false;
			        }
			       	  
			    });
			  },
			  error : function(){
				  alert("error");
			  }
			});
	}
	/**下拉框初始化(角色)  end  */
	
	
	
	
</script>
